function changeImg(){     
    var imgSrc = $("#imgObj");     
    var src = imgSrc.attr("src");     
    imgSrc.attr("src",chgUrl(src));     
}     
//时间戳     
//为了使每次生成图片不一致，即不让浏览器读缓存，所以需要加上时间戳     
function chgUrl(url){     
    var timestamp = (new Date()).valueOf();     
    url = url.substring(0,17);     
    if((url.indexOf("&")>=0)){     
        url = url + "×tamp=" + timestamp;     
    }else{     
        url = url + "?timestamp=" + timestamp;     
    }     
    return url;     
}     

//getContextPath
function getContextPath() {
    var pathName = document.location.pathname;
    var index = pathName.substr(1).indexOf("/");
    var result = pathName.substr(0,index+1);
    return result;
} 

function isRightCode(){    
	var objs = document.getElementById("error");

	if (document.loginFrm.userid.value.length==0) {
		//alert("请输入用户名");
		objs.innerHTML= "<font color ='red'>" + "用户名不能为空!" + "</font>";
		return false;
	}
	if (document.loginFrm.password.value.length==0) {
		//alert("请输入密码");
		objs.innerHTML= "<font color ='red'>" + "密码不能为空!" + "</font>";
		return false;
	}
	if (document.loginFrm.veryCode.value.length==0) {
		//alert("请输入验证码");
		objs.innerHTML= "<font color ='red'>" + "验证码不能为空!" + "</font>";
		return false;
	}     
	
	//check the verify code
    var code = $("#veryCode").attr("value");     
    //alert();   
    //code = "veryCode=" + code;
    var jsonCode = {veryCode : code};
    var result = true;
    $.ajax({     
        type:"POST",     
        url:getContextPath()+"/user/checkCode.do",//url:"ResultServlet",
        async:false,
        data: jsonCode, //code,     
        success:function(data) {
    		if (data=="CertNull") {
    			objs.innerHTML= "<font color ='red'>" + "验证码不能为空!" + "</font>";
    			result = false;
    		}
    		else if (data=="CertError") {
    			objs.innerHTML= "<font color ='red'>" + "验证码错误!" + "</font>";
    			//changeImg
    			changeImg();
    			result = false;
    		}
    	}	
    });  
    
    if(result == false) {
    	return result;
    }
    
    //check the username and password
    var username = $("#userid").attr("value");
    var password = $("#password").attr("value");
    //code="username="+username+"&&password="+password;
    jsonCode = {username: username, password: password};
    $.ajax({     
        type:"POST",     
        url:getContextPath()+"/user/authorize.do", //"CheckAccountServlet",
        async:false,
        data:jsonCode, //code,     
        success:function(data) {
    		if (data=="accountInvalid") {
    			objs.innerHTML= "<font color ='red'>" + "用户名或密码不正确!" + "</font>";
    			result = false;
    		}	
    	}
    });  
    
    
    return result;
}     
  
